package com.module.aichat.ui.schedule

import androidx.core.view.isVisible
import com.alibaba.android.arouter.facade.annotation.Route
import com.common.app.base.AppBackPressedFragment
import com.common.app.core.RouterHub
import com.common.base.app.extras.*
import com.common.base.utils.*
import com.common.base.utils.StatusBarUtils.setStatusBarHeight
import com.module.aichat.databinding.AichatFragmentMainBinding
import com.scwang.smart.refresh.header.ClassicsHeader
import com.scwang.smart.refresh.layout.api.RefreshLayout
import com.scwang.smart.refresh.layout.listener.OnRefreshLoadMoreListener


/**
 * 作者：sosou
 * <p>
 * 版本：1.0
 * <p>
 * 创建日期：2025/06/25
 * <p>
 * 描述：AI会话模块首页
 * <p>
 * 修订历史：
 */
@Route(path = RouterHub.ROUTER_AICHAT_FRAGMENT)
class AiChatFragment : AppBackPressedFragment<AichatFragmentMainBinding, AiChatViewModel>() {

    override fun getViewModel(): Class<AiChatViewModel> = AiChatViewModel::class.java

    override fun getViewBinding() = AichatFragmentMainBinding.inflate(layoutInflater)

    override fun initViews() {
        super.initViews()
        setStatusBarHeight(mViewBinding.statusView, 0)
    }

    override fun lazyInitData() {
        super.lazyInitData()

        StatusBarUtils.setStatusBarForegroundColor(activity, true)
    }

    override fun initEvents() {
        super.initEvents()

        mViewBinding.pdView.setEnableRefresh(false)
        mViewBinding.pdView.setEnableLoadMore(false)
//        getRefreshHeader()?.let { mViewBinding.pdView.setRefreshHeader(it) }
        mViewBinding.pdView.setRefreshHeader(ClassicsHeader(activity))
        mViewBinding.pdView.setOnRefreshLoadMoreListener(object : OnRefreshLoadMoreListener {
            override fun onLoadMore(refreshLayout: RefreshLayout) {}
            override fun onRefresh(refreshLayout: RefreshLayout) {
                StatusBarUtils.setStatusBarForegroundColor(activity, true)
                refreshLayout.layout.postDelayed({
                    StatusBarUtils.setStatusBarForegroundColor(activity, false)
                    mViewBinding.pdView.finishRefresh()
                }, 1000)
            }
        })

    }

    override fun onSupportVisible() {
        super.onSupportVisible()
        mViewBinding.animationTotal.isVisible.no {
            StatusBarUtils.setStatusBarForegroundColor(
                activity,
                false
            )
        }.otherwise {
            StatusBarUtils.setStatusBarForegroundColor(activity, true)
        }
//        UmengAgentHelper.onEvent(EventUmengAgent.visit_find_home)
//        ReportEventManager.reportEventStart(EventValue.EVENT_FINE_INDEX)

    }

    override fun onSupportInvisible() {
        super.onSupportInvisible()
//        ReportEventManager.reportEventEnd(EventValue.EVENT_FINE_INDEX)
    }

    override fun onDestroyView() {
        super.onDestroyView()
    }

    override fun onBackPressedSupport(): Boolean {
        return true
    }
}